/**
 * 3
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-11 下午2:48
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct node {
    string name;
    int sort1;
    int sort2;

    node() {

    }

    node(string name, int sort1, int sort2) {
        this->name = name;
        this->sort1 = sort1;
        this->sort2 = sort2;
    }
};

bool cmp1(node a, node b) {
    return a.sort1 < b.sort1;
}

bool cmp2(node a, node b) {
    return a.sort2 < b.sort2;
}

int main() {
    vector<node> vec = {{"ace", 8, 4},
                        {"bre", 2, 3},
                        {"cat", 5, 2},
                        {"dog", 1, 1}};
    string s, type;
    cin >> s >> type;
    if (s == "sort1") {
        sort(vec.begin(), vec.end(), cmp1);
    } else {
        sort(vec.begin(), vec.end(), cmp2);
    }

    if (type == "asc") {
        for (int i = 0; i < vec.size(); ++i) {
            cout << vec[i].name << endl;
        }
    } else {
        for (int i = vec.size() - 1; i >= 0; i--) {
            cout << vec[i].name << endl;
        }
    }
    return 0;
}